package string;

public class StringDemo {
    public static void main(String[] args) {




        String s1 = "123abc";
        String s2 = "123abc";
        System.out.println(s1==s2);
        String s3 = "123abc";
        System.out.println(s2==s3);

/*
常见面试题：
String str = new String("hello");
上述一句话创建了几个字符串对象？
答案：2个字符串对象
分别是：
1：字面亮“hello”会创建一个字符串对象并存入常量池中
2：new String会创建一个字符串对象只不过内容引用了“hello”对象




 */




        String s4 = new String("123abc");
        System.out.println("s1:"+s1);
        System.out.println("s4:"+s4);
        System.out.println(s1==s4); //false




        String s5 = "123" + "abc";

        System.out.println("s5:"+s5);
        System.out.println(s1==s5); //true

        String s = "123";
        String s6 = s+"abc";
        System.out.println("s6:"+s6);
        System.out.println(s1==s6); //false




        s1 = s1 + "!";
        System.out.println("s1:"+s1); //123abc
        System.out.println(s1==s2);   //false,s1不再指向原对象
        System.out.println("s2:"+s2);
        System.out.println("s3:"+s3);













    }
}
